package org.example.controller;

import org.example.commonapi.domain.onlineCode.OiCode;
import org.example.commonapi.domain.onlineCode.OjCode;
import org.example.commonapi.domain.R;
import org.example.service.CommitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 提交代码
 */

@RestController
@RequestMapping("/oj/commit")
public class CommitController {
    @Autowired
    private CommitService commitService;

    /**
     * 提交OI代码
     * @param oiCode oi代码
     * @return 返回结果
     */
    @PostMapping("/oi")
    public R<Object> commitOi(@RequestBody OiCode oiCode){
        System.out.println(oiCode.toString());
        return commitService.commitOi(oiCode);
    }

    /**
     * 提交OJ代码
     * @param ojCode oj代码
     * @param request http请求
     * @return 返回结果
     */
    @PostMapping("/oj")
    public R<Object> commitOj(@RequestBody OjCode ojCode, HttpServletRequest request){
        return commitService.commitOj(ojCode,request);
    }
}
